2026-09-20 · linux, class-notes
Most commands follow the same general shape:
Class notes · William Shotts, The Linux Command Line · Chapter 3
Quick reference: the short version of this chapter is the Chapter 3 cheat sheet.
By the end of these notes you should be able to:
Most commands follow the same general shape:
command -options arguments | | | | | +-- what to act on (files, directories, names) | +------------ how to behave (change the command's output) +---------------------- the program to run ls -lt /var/logHere ls is the command, -lt the options, and /var/log the argument.
Style
Looks like
Notes
Short
-l, -a, -t
A single dash and one letter. Several can be joined: -lat = -l -a -t
Long
--all, --reverse
Two dashes and a word. Easier to read, especially in scripts
Many options exist in both forms: ls -a and ls --all do the same thing.
Note: these conventions come from the GNU tools used on most Linux systems. Some commands (and other Unix systems) differ, so check a command's help when in doubt — chapter 5 covers how.
Option
Long form
Does
-a
--all
Show all files, including hidden ones (and . and ..)
-A
--almost-all
Like -a, but leaves out . and ..
-d
--directory
Show the directory itself, not its contents — use with -l
-F
--classify
Add a symbol to each name: / directory, * executable, @ link
-h
--human-readable
Sizes in K, M, G (with -l)
-l
Long format
-r
--reverse
Reverse the sort order
-S
Sort by size, largest first
-t
Sort by modification time, newest first
Goal
Command
See everything, including hidden files, in detail
ls -la
Find the newest log files
ls -lt /var/log
Find the oldest instead
ls -ltr /var/log
Find the biggest files, with readable sizes
ls -lSh
Check the permissions of a directory, not its contents
ls -ld /tmp
See at a glance which entries are directories or programs
ls -F
Why -d matters: ls -l /tmp lists what's inside /tmp. To see the permissions on /tmp itself, you need ls -ld /tmp.
ls -ltr is a troubleshooting favourite: the most recently changed files land at the bottom, right above your prompt.
-rwxr-xr-x 1 andrew andrew 20 Sep 19 14:41 backup lrwxrwxrwx 1 andrew andrew 9 Sep 19 14:41 link.txt -> notes.txt -rw-r--r-- 1 andrew andrew 6 Sep 19 14:41 notes.txt drwxr-xr-x 2 andrew andrew 4096 Sep 19 14:40 DocumentsTaking the first line field by field:
Field
Example
Meaning
1
-rwxr-xr-x
File type (first character), then permissions for owner, group and others
2
1
Number of hard links to the file
3
andrew
Owner (user)
4
andrew
Group
5
20
Size in bytes
6
Sep 19 14:41
Last modification date and time
7
backup
Name
First character
Type
Regular file
d
Directory
l
Symbolic link — the name shows link -> target
c / b
Character / block device (in /dev)
The nine characters after the type are three sets of rwx: for the owner, the group and everyone else. -rwxr-xr-x means the owner can read, write and run; the group and others can read and run. Permissions are covered fully later in the book (and in the TryHackMe module 3 notes).
-rw-r----- 1 root adm 218K Sep 19 09:12 auth.log1. Type: - — a regular file. 2. Permissions: owner root can read and write; group adm can read; others have no access. 3. Size and date: 218 KB, last written at 09:12. 4. What it tells you: a normal user can't read this log unless they're in the adm group. That's deliberate — authentication logs are sensitive.
Note: timestamps for files older than about six months show the year instead of the time.
Because Linux doesn't rely on extensions, you need a way to find out what a file really contains. file looks at the content — mainly the first bytes (the "magic number") — and reports the type.
$ file notes.txt backup link.txt /bin/ls picture.png notes.txt: ASCII text backup: Bourne-Again shell script, ASCII text executable link.txt: symbolic link to notes.txt /bin/ls: ELF 64-bit LSB pie executable, x86-64, ... picture.png: PNG image data, 800 x 600, 8-bit/color RGBA, non-interlaced
ELF is the executable format for Linux programs — the equivalent of a Windows .exe.
The same check on a real PDF would report PDF document, version 1.7.
Many important Linux files are plain text: configuration files in /etc, logs in /var/log, scripts. less lets you read them one screen at a time, scroll back and search.
less /etc/os-release
Key
Does
Space or Page Down
Forward one page
b or Page Up
Back one page
Up / Down arrows
One line at a time
G
Jump to the end
g
Jump to the start
/text
Search forward for "text"
n
Next match
h
Help
q
Quit
It replaced an older pager called more, which could only move forward. The joke is that "less is more" — less does everything more does, and more. A pager is simply a program that shows text one page at a time.
Caution: less is the safe way to look at a file. Opening a configuration file in an editor just to read it risks accidental changes.
Linux systems follow a common layout, the Filesystem Hierarchy Standard (FHS). Knowing it means you can find your way around almost any distribution.
Directory
Contains
/
The root of the tree
/bin
Essential programs for the system to boot and run
/boot
The Linux kernel, initial RAM disk and bootloader files
/dev
Device nodes — Linux treats devices as files
/etc
System-wide configuration files, all plain text
/home
Normal users' home directories
/lib
Shared libraries used by core programs
/lost+found
Files recovered after a file system error (on ext file systems)
/media
Mount points for removable media (USB sticks) on desktops
/mnt
Mount points for manually mounted devices
/opt
Optional, usually commercial, software
/proc
A virtual file system: a window into the kernel and running processes
/root
The root user's home directory
/sbin
System administration programs
/tmp
Temporary files; often cleared at reboot
/usr
Most programs and support files for users
/usr/bin
The bulk of installed programs
/usr/lib
Shared libraries for programs in /usr/bin
/usr/local
Software installed locally by the administrator, not by the distribution
/usr/sbin
More system administration programs
/usr/share
Shared data: documentation, icons, default configurations
/usr/share/doc
Documentation for installed packages
/var
Data that changes: logs, mail, databases, caches
/var/log
Log files — one of the first places to look when troubleshooting
Worth exploring with less: /etc/passwd (user accounts), /etc/fstab (file systems mounted at boot), /etc/os-release (distribution details) and /proc/cpuinfo (CPU details).
Note: many modern distributions have merged /bin, /sbin and /lib into their /usr equivalents. On those systems /bin is a symbolic link to /usr/bin — you'll see bin -> usr/bin in ls -l /.
A symbolic link (symlink, soft link) is a special file that points to another file or directory by name — like a Windows shortcut, but handled by the operating system itself, so every program follows it.
lrwxrwxrwx 1 root root 7 Apr 22 2024 bin -> usr/bin
Why they're used: a program might need a library called libfoo.so, while the real file is libfoo.so.2.6. A symlink named libfoo.so points at the current version. Upgrading means installing the new file and moving the link — every program follows automatically.
A hard link is a second directory entry for the same data on disk. Both names are equally "real". The second field of ls -l counts them. Chapter 4 shows how to create both kinds and compares them in detail.
Symbolic link
Hard link
Points to
A name (path)
The data itself
Shown in ls -l as
l type with -> target
An ordinary file; link count above 1
If the original is deleted
Link breaks (dangling)
Data survives through the other name
Term
Definition
Option
Modifies how a command behaves, e.g. -l
Argument
What a command acts on, e.g. a filename
Short option / long option
-a style / --all style
Long listing
Detailed ls -l output
Link count
Number of hard links (names) pointing to a file's data
Owner / group
The user and group a file belongs to
file
Identifies a file's type from its contents
Magic number
Bytes at the start of a file that identify its format
ELF
The executable and linkable format — Linux's program format
Pager
A program that displays text one screen at a time
less
The standard Linux pager
FHS
Filesystem Hierarchy Standard — the common Linux directory layout
/etc
Directory of system configuration files
/var/log
Directory of log files
/proc
Virtual file system exposing kernel and process information
/dev
Directory of device files
Symbolic link
A file that points to another file by name
Hard link
An additional name for the same file data
Dangling link
A symbolic link whose target no longer exists